package com.upf1sh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.upf1sh.bean.Snapshot;
import com.upf1sh.service.SnapshotService;
import com.upf1sh.utils.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/snapshot")
public class SnapshotController {
    @Resource
    private SnapshotService snapshotService;

    @RequestMapping("/getSnapshotById")
    public Result getSnapshot() {
        return Result.ok().data("snapshot", snapshotService.getSnapshot(1));
    }

    @PostMapping("/getSnapshotByPage")
    public Result getAllAudio(@RequestParam(defaultValue = "1") int pageNum) {
        Page<Snapshot> page = new Page(pageNum, 10);
        Page<Snapshot> files = snapshotService.findAllSnapshotByPage(page);
        return Result.ok().data("items", files);
    }

    @RequestMapping("/getAllSnapshot")
    public Result getAllSnapshot() {
        return Result.ok().data("snapShotList", snapshotService.getAllSnapshot());
    }

    @RequestMapping("/saveSnapshot")
    public Result saveSnapshot(MultipartFile file, String belong, String description) {
        return Result.ok().data("result", snapshotService.saveSanpshot(file, belong, description));
    }


}
